package com.pr.makfilm.user.pages.room.create.preview;

import com.pr.makfilm.domain.Room;
import com.pr.makfilm.domain.RoomPlace;
import com.pr.makfilm.domain.RoomPlaceTypeEnum;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;

/**
 * Created with IntelliJ IDEA.
 * User: Pawel
 * Date: 09.10.13
 * Time: 17:47
 * To change this template use File | Settings | File Templates.
 */
public class PreviewCell extends Panel
{
   public static final String FREE_PLACE_CLASS = "cell btn btn-sm active btn-success no-border";

   public static final String BLOCKED_PLACE_CLASS = "cell btn btn-sm active btn-danger no-border";

   public static final String EMPTY_PLACE_CLASS = "cell btn btn-sm disabled no-border";

   public PreviewCell(String id, IModel<RoomPlace> placeModel)
   {
      super(id, placeModel);
   }

   @Override
   protected void onInitialize()
   {
      super.onInitialize();
      add(new Label("cell", new PropertyModel<String>(getDefaultModel(), "label"))
      {
         @Override
         protected void onComponentTag(ComponentTag tag)
         {
            super.onComponentTag(tag);
            RoomPlace place = (RoomPlace) PreviewCell.this.getDefaultModelObject();
            if (place == null || StringUtils.isEmpty(place.getSid()))
            {
               tag.put("class", EMPTY_PLACE_CLASS);
            }
            else if (place.getType() == RoomPlaceTypeEnum.FREE)
            {
               tag.put("class", FREE_PLACE_CLASS);
            }
            else if (place.getType() == RoomPlaceTypeEnum.BLOCKED)
            {
               tag.put("class", BLOCKED_PLACE_CLASS);
            }
         }
      });
   }
}
